let Card = require('./card.js');
let Random = require('./random.js');
module.exports = Poker;

let colors = new Array("黑桃", "红桃", "梅花", "方片", "");
let values = new Array("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "小王", "大王");

Math.seed = 10; 
Math.randomInt = function(min,max){
	Math.seed=Math.seed*214013+2531011;
    let seed = Math.seed;
	return min+(seed)%(max-min+1);
};

function Poker(){
    this._random = new Random();
    this._cardList = new Array();
    for (let i = 0; i < 54; i++) {
        this._cardList.push(new Card(i));
    }
}
let shuffle = function (arr) {
    for (let j, x, i = arr.length-1; i>=0; i--){
        // j = parseInt(Math.random() * i);
        j = Math.randomInt(0,arr.length);
        x = arr[i]; arr[i] = arr[j]; arr[j] = x;
    }
    return arr;
};
Poker.prototype.shuffle = function () {
    let arr = this._cardList;
    for (let j, x, i = arr.length-1; i>=0; i--){
        // j = parseInt(Math.random() * i);
        j = this._random.randomInt(0,arr.length-1);
        x = arr[i]; arr[i] = arr[j]; arr[j] = x;
    }
    return arr;
};

// 发牌
Poker.prototype.deal = function () {
    let cards = this.shuffle();
    // 抽三张底牌
    let holes = [];
    holes.push(cards.pop());
    holes.push(cards.pop());
    holes.push(cards.pop());

    function getCards(id) {
        let cc = new Array();
        for (let i = id * 17; i < id * 17 + 17; i++) {
            cc.push(cards[i]);
        }
        return cc;
    }
    
    return [holes,getCards(0),getCards(1),getCards(2),];
};